Structural sharing topic

When new data arrives, replaceEqualDeep keeps the parts equal to the cached data as the same instances, so identical checks and rebuilds can skip what did not change. StructurallyShareable lets your own value classes take part; StructuralSharing and noStructuralSharing configure it per query.

Classes

StructurallyShareable<T>
A value class that structural sharing may walk into.

Functions

noStructuralSharing<TQueryData>() → StructuralSharing<TQueryData>
The opt-out for QueryOptions.structuralSharing: every write keeps the incoming value, so every refetch reports a new instance, and so does every select. TanStack Query spells this structuralSharing: false.
replaceEqualDeep<T>(Object? previous, T next, [int depth = 0]) → T
Returns previous when next is deep-equal to it, and otherwise next with every deep-equal part swapped for the instance previous already held. This is the default structural sharing of every query, and the reason a refetch that brings back the same data does not rebuild anything: unchanged data keeps its instance, so identical checks and == short-circuits downstream stay cheap and true.

Typedefs

StructuralSharing<TQueryData> = TQueryData Function(TQueryData? previous, TQueryData next)
Decides what is written into the cache when new data arrives, given what was there before.